﻿// -----------------------------------------------------------------------
// <copyright file="SPWebPartHelper.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace AgileShare.Framework.Library.Helpers
{

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public static class SPWebPartHelper
    {
        public static string ConvertXML(string XMLDoc, string XSLTPath)
        {
            // Required to prevent 401 error
            var resolver = new XmlUrlResolver { Credentials = CredentialCache.DefaultCredentials };
            var settings = new XsltSettings(true, true);

            // End
            var doc = new XPathDocument(new StringReader(XMLDoc));
            var xslt = new XslCompiledTransform();
            xslt.Load(XSLTPath, settings, resolver);

            var sw = new StringWriter();
            xslt.Transform(doc, null, sw);
            return sw.ToString();
        }
    }
}
